package com.cloudshop.service.common.config.filter;

import com.cloudshop.service.common.filter.GlobalFilter;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 全局过滤器配置.
 *
 * @author 宫新程
 * @since 2019/3/29 15:18
 */
@Configuration
public class GlobalFilterConfigBean {

  @Bean
  public GlobalFilter globalFilterBean() {
    return new GlobalFilter();
  }

  /** 全局过滤器配置. */
  @Bean
  public FilterRegistrationBean globalFilter() {
    FilterRegistrationBean<GlobalFilter> registrationBean = new FilterRegistrationBean<>();
    registrationBean.setFilter(globalFilterBean());
    registrationBean.setName("globalFilter");
    List<String> urlPatterns = new ArrayList<>();
    urlPatterns.add("/*");
    registrationBean.setUrlPatterns(urlPatterns);
    registrationBean.setOrder(-2147482648);
    return registrationBean;
  }
}
